/*
 *  \file ClientKB.h
 *  GRE
 *
 *  Created by Kutlak Roman on 24/01/2012.
 *  Copyright 2012 Kutlak Roman. All rights reserved.
 *
 */

#ifndef ClientKB_h 
#define ClientKB_h

#include <netinet/in.h>

#include "KnowledgeBase.h"
#include "ServerUtils.h"

namespace kutlak {
namespace roman {
namespace gre {
    
    /*!
     * \brief A one line description of the class. 
     * 
     * #include "XX.h" <BR> 
     * -llib 
     * 
     * A longer description. 
     * 
     * @see something 
     */
    class ClientKB : public KnowledgeBase { 
    public: 
#pragma mark -
#pragma mark lifecycle
        //!Default constructor. 
        ClientKB(const std::string& host = "127.0.0.1");
        
        //! Destructor.
        virtual ~ClientKB(void);
        
#pragma mark -
#pragma mark operations
        void SendCommand(ServerCommand c) const;
        
        void SendId(int id) const;
        
        void SendString(const std::string& str) const;
        
        void SendProperty(const Property& p) const;
        
        void ReadEntityPtrVector(std::vector<EntityPtrT>& entities) const;
        
        EntityPtrT ReadEntityPtr() const;
        
        //! Returns a copy of the entities held by this KnowledgeBase.
        virtual std::vector<EntityPtrT> Entities() const;
        
        //! Returns entities of speficied type (including subclasses).
        virtual std::vector<EntityPtrT> EntitiesOfType(const Property& type) const;
        
        //! Returns a copy of the entities held by this KnowledgeBase.
        virtual std::vector<EntityPtrT> Entities(const Property& pattern) const ;
        
        //! Returns the pointer to the Entity with given Id or null pointer.
        virtual EntityPtrT EntityPtrById(int entityId) const;
        
        //! Returns the pointer to the Entity with given name or null pointer.                
        virtual EntityPtrT EntityPtrByName(const std::string& name) const;
        
        size_t Size() const;
        
    private:
        int mSocket;
        unsigned int mAddressLen;
        struct sockaddr_in mAddress;
    };
    
} // end namespace GRE
}
}
#endif // ClientKB_h
